package com.google.code.mergeinformer.constraint.impl;

import com.google.code.mergeinformer.constraint.CvsUrl;
import com.google.code.mergeinformer.service.VcsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Configurable;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;

/**
 * @author Dmitry Golubev
 */
@Configurable
public class CvsUrlValidator implements ConstraintValidator<CvsUrl, String> {

    @Autowired
    private VcsService vcsService;

    @Override
    public void initialize(CvsUrl cvsUrl) {
    }

    @Override
    public boolean isValid(String value, ConstraintValidatorContext context) {
        return vcsService.isUrlValid(value);
    }
}
